//
//  StatusCellBottomView.m
//  OCMicroBlog
//
//  Created by 002 on 15/11/7.
//  Copyright © 2015年 002. All rights reserved.
//

#import "StatusCellBottomView.h"
#import "UIButton+Extention.h"
#import "masonry.h"
#import "UIView+Extention.h"

@interface StatusCellBottomView ()

// 转发按钮
@property(nonatomic,strong) UIButton *retweetButton;

// 评论按钮
@property(nonatomic,strong) UIButton *commentButton;

// 点赞按钮
@property(nonatomic,strong) UIButton *likeButton;

@end

@implementation StatusCellBottomView

// 构造函数
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

#pragma mark - 设置界面
- (void)setupUI {
    
    // 1. 添加控件
    [self addSubview:self.retweetButton];
    [self addSubview:self.commentButton];
    [self addSubview:self.likeButton];
    
    // 2. 布局
    // 转发
    [self.retweetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    // 评论
    [self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.retweetButton.mas_right);
        make.top.equalTo(self.mas_top);
        make.width.equalTo(self.retweetButton.mas_width);
        make.height.equalTo(self.retweetButton.mas_height);
    }];
    
    // 点赞
    [self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.commentButton.mas_right);
        make.top.equalTo(self.mas_top);
        make.width.equalTo(self.commentButton.mas_width);
        make.height.equalTo(self.commentButton.mas_height);
        
        make.right.equalTo(self.mas_right);
    }];
    
    // 3. 分割视图线
    UIView *sep1 = [UIView sepView];
    UIView *sep2 = [UIView sepView];
    
    [self addSubview:sep1];
    [self addSubview:sep2];
    
    CGFloat sepWidth = 0.5;
    CGFloat sepScale = 0.4;
    
    [sep1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.retweetButton.mas_right);
        make.centerY.equalTo(self.retweetButton.mas_centerY);
        make.width.equalTo([NSNumber numberWithFloat:sepWidth]);
        make.height.equalTo(self.retweetButton.mas_height).multipliedBy(sepScale);
    }];
    
    [sep2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.commentButton.mas_right);
        make.centerY.equalTo(self.commentButton.mas_centerY);
        make.width.equalTo([NSNumber numberWithFloat:sepWidth]);
        make.height.equalTo(self.commentButton.mas_height).multipliedBy(sepScale);
    }];
    
}

#pragma mark - 懒加载
- (UIButton *)retweetButton {
    if (!_retweetButton) {
        _retweetButton = [UIButton initWithTitle:@"转发" color:[UIColor lightGrayColor] fontSize:12 imageName:@"timeline_icon_retweet"];
    }
    return _retweetButton;
}

- (UIButton *)commentButton {
    if (!_commentButton) {
        _commentButton = [UIButton initWithTitle:@"评论" color:[UIColor lightGrayColor] fontSize:12 imageName:@"timeline_icon_comment"];
    }
    return _commentButton;
}

- (UIButton *)likeButton {
    if (!_likeButton) {
        _likeButton = [UIButton initWithTitle:@"赞" color:[UIColor lightGrayColor] fontSize:12 imageName:@"timeline_icon_unlike"];
    }
    return _likeButton;
}
@end
